<template>
  <div class="navbar-msg">
    <el-popover placement="bottom" width="300" trigger="hover" v-model="visable">
      <el-badge slot="reference" :value="navbarMsg.total" :max="99" :hidden="navbarMsg.total <= 0">
        <i class="el-icon-bell"></i>
      </el-badge>
      <el-table class="el-table--navbar" :data="navbarMsg.list" size="mini" :show-header="false" @row-click="rowClick">
        <el-table-column width="260" property="title" label="标题" :show-overflow-tooltip="true"></el-table-column>
      </el-table>
      <div class="navbar-msg_footer" v-show="navbarMsg.total > navbarMsg.limit">
        <a @click="gotoRouteHandle(menuId)">{{ $t('sysmsg.seeMore') }}</a>
      </div>
    </el-popover>
  </div>
</template>

<style>
.el-table--navbar .el-table__row td {
  font-size: 14px;
  cursor: pointer;
}
.navbar-msg_footer {
  margin-top: 5px;
  margin-right: 10px;
  font-size: 12px;
  float: right;
}
.navbar-msg_footer a:hover {
  cursor: pointer;
}
</style>

<script>
import { menuId } from '@/views/modules/msg/msgRecord.json'
export default {
  name: 'navbar-msg',
  data () {
    return {
      visable: false,
      menuId: menuId
    }
  },
  props: {
    navbarMsg: {
      type: Object,
      required: true
    }
  },
  methods: {
    // 通过menuId与动态(菜单)路由进行匹配跳转至指定路由
    gotoRouteHandle (menuId, params) {
      let route = window.SITE_CONFIG['dynamicMenuRoutes'].filter(item => item.meta.menuId === menuId)[0]
      if (route) {
        this.$router.push({ name: route.name, params: params || route.params })
        this.visable = false
      }
    },
    rowClick (row) {
      this.gotoRouteHandle(this.menuId, row)
    }
  }
}
</script>
